<?php include('include/entete.html'); ?>

<br/><br/>

<div class="contenu">
	<table align="center" width="100%" cellpadding="3" cellspacing="0">
	<tr>
		<td id="cell1">Detail emplacement</td>
	</tr>
	<tr>
		<td id="cell2">
 
<?php
	// Récupération de l'ID de l'emplacement
	$pays = $_GET['pays'];
	$id = (int)$_GET['id'];
?>
 
<br/>
<b>/<a href="index.php">Liste Pays</a>/<a href="liste_emplacements.php?pays=<?php echo $pays; ?>">Liste emplacements</a></b>

<?php

	try {
		$db = new PDO('mysql:host=localhost;dbname=campingcar', 'root', '');
		//echo 'Connected to database';
    }
	catch(PDOException $e) {
		echo $e->getMessage();
    }
	
	$select_empl = $db->prepare('SELECT e.*, t.type FROM emplacement e, type_emplacement t WHERE e.type_emplacement_id=t.id AND e.id='.$id);
	$select_empl->execute(array(1));
	$empl = $select_empl->fetchAll();
?>

<div class="table">
<table border="0" width="100%">
	<tr><th class="thead">Id (bd)</th><td class="ligne2"><?php echo $empl[0]['id'] ?></td></tr>
	<tr><th class="thead">Num (site)</th><td class="ligne2"><?php echo $empl[0]['num'] ?></td></tr>
	<tr><th class="thead">Type</th><td class="ligne2"><?php echo $empl[0]['type'] ?></td></tr>	
	<tr><th class="thead">Localite</th><td class="ligne2"><?php echo $empl[0]['localite'] ?></td></tr>
	<tr><th class="thead">GPSN</th><td class="ligne2"><?php echo $empl[0]['GPSN'] ?></td></tr>
	<tr><th class="thead">GPSE</th><td class="ligne2"><?php echo $empl[0]['GPSE'] ?></td></tr>
	<?php
	if (doubleval($empl[0]['GPSE'])<0) {
		echo '<tr><th class="thead">GPS (MapSource)</th><td class="ligne2">N'.doubleval($empl[0]['GPSN']).' W'.abs(doubleval($empl[0]['GPSE'])).'</td></tr>';
	} else {
		echo '<tr><th class="thead">GPS (MapSource)</th><td class="ligne2">N'.doubleval($empl[0]['GPSN']).' E'.doubleval($empl[0]['GPSE']).'</td></tr>';
	}
	?>
	<tr><th class="thead">Adresse</th><td class="ligne2"><?php echo $empl[0]['adresse'] ?></td></tr>
	<tr><th class="thead">Tarifs</th><td class="ligne2"><?php echo $empl[0]['tarifs'] ?></td></tr>
	<tr><th class="thead">Type de borne</th><td class="ligne2"><?php echo $empl[0]['type_de_borne'] ?></td></tr>
	<tr><th class="thead">Eau potable</th><td class="ligne2"><?php echo $empl[0]['eau_potable'] ?></td></tr>
	<tr><th class="thead">Vidange_eaux_usees</th><td class="ligne2"><?php echo $empl[0]['vidange_eaux_usees'] ?></td></tr>
	<tr><th class="thead">Vidange WC</th><td class="ligne2"><?php echo $empl[0]['vidange_wc'] ?></td></tr>
	<tr><th class="thead">220v</th><td class="ligne2"><?php echo $empl[0]['v220'] ?></td></tr>
	<tr><th class="thead">WC publics</th><td class="ligne2"><?php echo $empl[0]['wc_publics'] ?></td></tr>
	<tr><th class="thead">Autres services</th><td class="ligne2"><?php echo $empl[0]['autres_services'] ?></td></tr>
	<tr><th class="thead">Autres infos</th><td class="ligne2"><?php echo $empl[0]['autres_infos'] ?></td></tr>
	<tr><th class="thead">Date creation</th><td class="ligne2"><?php echo $empl[0]['creation_date'] ?></td></tr>
	<tr><th class="thead">Date modification</th><td class="ligne2"><?php echo $empl[0]['last_update_date'] ?></td></tr>
</table>
</table>
</div>	

</td>
</tr>
</table>
</div>

<br/>

<div class="contenu100">
	<table align="center" width="100%" cellpadding="3" cellspacing="0">
	<tr>
		<td id="cell1">Commentaires</td>
	</tr>
	<tr>
		<td id="cell2">
	
<div class="table">
<table border="0" width="100%">
	<tr class="thead">
		<th>Id</th>
		<th>Date</th>
		<th>User</th>
		<th>Commentaire</th>
	</tr>
<?php
	
	$sql_comm = "SELECT * FROM commentaire WHERE emplacement_id=".$id." ORDER BY date_post DESC";
	$select_messages = $db->prepare($sql_comm);
	$select_messages->execute();

	$couleur = array(0 => "ligne1", 1 => "ligne2");
	$i = 0;
	foreach($select_messages->fetchAll() as $rec) {
		echo '<tr class="'.$couleur[$i%2].'">';
		echo '<td>'.$rec['id'].'</td>';
		echo '<td>'.$rec['date_post'].'</td>';
		echo '<td>'.$rec['user'].'</td>';
		echo '<td>'.$rec['msg'].'</td>';
		echo '</tr>';
		$i++;
	}
?>
</table>
</div>	
 
</td>
</tr>
</table>
</div>

<br/><br/>
 
<?php include('include/piedPage.html'); ?>
            
